package com.cykj.pos.mapper;

import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.core.domain.entity.SysUser;
import com.cykj.pos.domain.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cykj.pos.domain.dto.*;
import com.cykj.pos.profit.dto.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 终端设备信息Mapper接口
 *
 * @author ruoyi
 * @date 2021-01-11
 */
@Repository
public interface BizPosMachineMapper extends BaseMapper<BizPosMachine> {
    String doCallBacks(String s);

    int interRecords(BizPosMachineStatusRecords inbizPosMachineStatusRecords);

    int updatebizPosMachine(String sn);

    BizPosMachineStatusRecords getRecordsBySnCode(String posCode);

    Long selVueCallBackmerchid(Long posId);

    Long posid(String s);

    int updataAllId(Long posId);

    List<BizPosMachine> selectAll(Long posId);

    BizPosType selectType(Long posType);

    BizPosMachine selectPosMachine(String posType);

    int insterAllEntry(BizMerchantEntry bizMerchantEntry);

    int selectAllStatusRecords(String posCode);

    int selectAllBizMerchantEntry(String posCode);

    int updateAllStatusRecords(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    int updateAllEntry(BizMerchantEntry bizMerchantEntry);

    int inserterAllStatusRecords(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    /**
     * 根据伙伴信息查询机器总量
     *
     * @param posId
     * @return
     */
    BizPosMachine selectposCode(Long posId);

    Integer insertbaarecords(BizAllocAdjRecords bizAllocAdjRecords);

    HuaBoDTO getPersonByIds(Long s, Long merchId);

    BizPosMachine poscode(Long s);

    Long selBizMerchantuserid(Long merchId);

    /**
     * Vue划拨列表
     *
     * @param bizPosMachine
     * @return
     */
    List<VueCallBack> getListHuaBo(VueCallBack bizPosMachine);

    /**
     * @author: haoran
     * @date: 2022/8/1
     * 方法名称： 查询merchId
     */
    Long selectMerchId(Long userId);

    /**
     * 根据伙伴信息查询机器总量
     *
     * @param merchantId
     * @return
     */
    Integer getPosMachineAllCountsByMerchId(Long merchantId);

    /**
     * 获取商户转移列表
     *
     * @param nickName
     * @return
     */
    List<MerchantsTransferDTO> getAllMerchantByNickName(String nickName);

    /**
     * 删除商pos机器和商户伙伴的对应关系
     *
     * @param posCode
     */
    void deleteMerchPosRelated(String posCode);

    /**
     * 验证是否存在这个用户
     *
     * @param posCode
     * @return
     */
    BizPosMachine selectPosCode(String posCode);

    /**
     * 验证设备临时表是否存在这个用户
     *
     * @param posCode
     * @return
     */
    BizPosMachineTemporaryDTO selectPosTemporaryCode(String posCode);

    /**
     * 仅能划拔本级终端
     *
     * @param terminalDTO
     * @return
     */
    List<TerminalDTO> getAllPos(PosTerminalDTO terminalDTO);

    /**
     * 仅能回调下拉下级终端
     *
     * @param terminalDTO
     * @return
     */
    List<TerminalDTO> getAllPosTwo(PosTerminalDTO terminalDTO);

    /**
     * 终端查询
     *
     * @param terminalDTO
     * @return
     */
    List<TerminalDTO> getAllPosNull(PosTerminalDTO terminalDTO);

    /**
     * Vue回调列表
     *
     * @param bizPosMachine
     * @return
     */
    List<VueCallBack> getListCallBack(VueCallBack bizPosMachine);

    /**
     * Vue执行回调
     *
     * @param code
     */
    void doCallBack(@Param("code")String code, @Param("userId")Long userId);

    /**
     * vue划拨时查询详细信息
     *
     * @param posId
     * @return
     */
    VueCallBack getPersonById(String posId);

    BizPosMachineSyncDTO selectBizPosMachinesn(String posCode);

    BizPosMachineSyncDTO selectBizPosMachineNewsn(String posCode);

    /**
     * vue划拨操作
     *
     * @param vueCallBack1
     * @return
     */
    int doTransfer(VueCallBack vueCallBack1);

    int doTransferEntry(VueCallBack vueCallBack1);

    /**
     * 获得品牌列表（包含pos机类型列表）
     *
     * @return
     */
    List<BizPosBrandType> getPosBrandList();

    /**
     * 盛付通绑定
     *
     * @return
     */
    boolean saveSftBind(SftBindDTO sftBindDTO);

    /**
     * 根据激活参数查询绑定信息
     *
     * @param sn
     */
    BizPosMachineStatusRecords getStfBySn(String sn);

    /**
     * 盛付通激活
     *
     * @param sftActivDTO
     * @return
     */
    int updateBySn(SftActivDTO sftActivDTO);

    /**
     * pos1.0激活
     *
     * @param snCode
     * @return
     */
    int updatePosOneRecords(String snCode);

    /**
     * 查询终端费率id
     *
     * @return
     */
    List<BizPosErminalRate> selectPosErminalRate();

    BizPosMachine selectPosMachineBySn(String sn);

    /**
     * 将excel数据导入数据库
     *
     * @param posMachine
     */
    int insertPosMachine(BizPosMachine posMachine);

    int updateSyncPosMachine(BizPosMachine bizPosMachine2);

    int delBizPosMachineTemporary(String posCode);

    int delBizPosMachine(String posCode);

    int insertBizFeesChargedAdd(BizFeesChargedAddDTO bizFeesChargedAddDTO);

    /**
     * 查询设备类型
     *
     * @param posType
     * @return
     */
    String selectPosType(String posType);

    /**
     * 设备品牌
     *
     * @param var1
     * @return
     */
    String selectVar1(String var1);

    void updatePosMachine(String snCode);

    void updatePosPosMachine(String snCode);

    void generateAllPosMerchantRelatedProcedure();

    @Select("SELECT var2 FROM biz_version_record")
    String getVar();

    /**
     * 存入设备表
     *
     * @param bizPosMachine
     */
    void insertPosMachineFictitious(BizPosMachine bizPosMachine);

    String selectMerchantEntryPhone(Long id);

    List<BizPosMachine> selectBizPosMachineAllList();

    /**
     * 设备绑定merchid 改成激活
     *
     * @param sn
     * @param merchId
     */
    void updatebizPosMachineMerchIdAndStatus(@Param("sn") String sn, @Param("merchId") Long merchId);

    @Select("select parent_id from biz_merch_parent_related where child_id = #{merchId} and node = 1")
    Long selectParentId(Long merchId);

    @Select("SELECT * FROM biz_merchant_entry")
    List<BizMerchantEntry> selectEntryAll();

    @Select("SELECT * FROM biz_profit_deatail where transaction_amount_id=#{uuid}")
    List<BizProfitDeatail> selectfenrun(String uuid);

    //terminal_no is null
    @Select("SELECT * FROM biz_pos_machine where terminal_no is null")
    List<BizPosMachine> selectBizPosMachinesSn();


    @Update("update biz_pos_machine set terminal_no=#{terminalNo} where pos_code=#{posCode}")
    int updateBizPosMachinesTerminalNo(BizPosMachine bizPosMachine11);

    @Select("SELECT * FROM biz_transaction_amount WHERE host_date = {hostDate} order by host_date desc ")
    List<SynchronizationDataDTO> selectUuidIsNull(String hostDate);

    @Select("SELECT pos_code FROM biz_pos_machine")
    List<BizPosMachine> timerGetAllPos();

    @Select("SELECT sn FROM biz_haofan")
    List<BizHaofan> selzyf();

    public BizRenRunSubsidiesDTO selectBizRenRunSubsidiesKeyWord(Long merchId);

    BizWallet selbizWallet(Long userId);

    /*
     * 通过userId查询merchId
     *
     * */
    Long setMerchId(Long userId);

    /*  函数*/
    void generateAllPosMerchantRelated();

    int selectIsTransfer(WalletNewDTO bizPosMachine);

    BizPosMachine selectPosMachineType(WalletNewDTO bizPosMachine);

    /**
     * 在设备管理中查询   查询选中的merch_id  pos类型
     *
     * @param posCode
     * @return
     */
    BizPosMachine selmerchId1(String posCode);

    /**
     * 积分账单    查询msg_id 获取选中人的user_id
     *
     * @param merchId1
     * @return
     */
    Long seluserid1(Long merchId1);

    /**
     * 合作伙伴   查询user_id  获取指定人的user_id
     *
     * @param merchId
     * @return
     */
    Long seluserid(Long merchId);

    /**
     * VUE设备转移
     *
     * @param merchId
     * @param posCode
     * @return
     */
    int updateMerchantsEquipmentVue(@Param("merchId") Long merchId, @Param("posCode") String posCode);

    int updateMerchantsEntry(@Param("merchId") Long merchId, @Param("id") Long id);

    Long selectMerchantsEntry(String posCode);

    void updatePosPosMachineActivateStatusNew(String posCode);

    SignatureDTO selectPosMoneyInfo(String merchantNo);

    /**
     * 获取厂商
     * @return
     */
    List<StorageEquipment> getManufacturer();

    /**
     * 获取设备型号
     * @param id
     * @return
     */
    List<StorageEquipment> getManufacturerModel(Long id);

    /**
     * 获取服务费
     * @param id
     * @return
     */
    List<StorageEquipment> getServiceCharge(Long id);

    StorageEquipment getManufacturerByid(String id);

    String getUnitType(String id);
    /**
     * 设备修改
     * @param bizPosMachine
     * @return
     */
    int updatePosPMachaine(BizPosMachine bizPosMachine);

    /**
     * 查询设备详情
     * @param posCode
     * @return
     */
    PospPosmachine getPosCodeInfo(String posCode);

    @Select("select dept_id from sys_user where user_id=#{userId}")
    int getDeptid(Long userId);

    @Update("UPDATE biz_pos_machine  SET merch_id = #{merchId} WHERE  pos_code = #{posCode}")
    int doTransfers(VueCallBack vueCallBack1);

    @Select("select * from sys_user where user_id=#{userId}")
    SysUser getUserByUserId(Long userId);

    @Select("select * from biz_merchant where merch_id=#{parentId}")
    BizMerchant getMerchantByMerchId(Long parentId);

    @Select("select count(1) from biz_no_user where user_id=#{userId}")
    Integer selectNoUser(Long userId);

    @Select("select r.* from biz_pos_machine_status_records r left join biz_merchant_info i on r.sn_code=i.pos_code where i.on_line='1' and r.id_card_no like concat('%', #{phone})")
    List<BizPosMachineStatusRecords> getRecordsByPhone(String phone);
    @Select("SELECT en.bankcardaccount FROM biz_entry_sn AS sn LEFT JOIN biz_merchant_entry AS en ON sn.entry_id = en.id WHERE sn.sn =#{snCode}")
    String selectBankCardnoByEntry(String snCode);
    @Select("select * from biz_merchant_info where pos_code=#{snCode}")
    BizMerchantInfo selectBankCardnoByInfo(String snCode);
    String selectAgentid(String posType);

    List<AllocationRelation> getAllocationRelationBySn(String sn);

    List<BizPosMachine> getPosMachineType(Long merchId);

    int getAllCount(@Param("channel")String channel,@Param("merchId") Long merchId);

    int getBindCount(@Param("channel")String channel,@Param("merchId") Long merchId);

    int getCanUseCount(@Param("channel")String channel,@Param("merchId") Long merchId);

    int getNoMineCount(@Param("channel")String channel,@Param("merchId") Long merchId);

    List<BizPosMachine> getPosMachineTransList(PosTerminalDTO posTerminalDTO);

    AllocationRelation getAllocationRelationBySnForServiceFlowInterval(PosTerminalDTO posTerminalDTO);

    List<String> getSnListByIds(@Param("posIdsList")List<Long> posIdsList);

    Double getMinServiceFee(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    Double getDefaulltMinServiceFee(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    Double getMinFlowFee(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    Double getDefaultMinFlowFee(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    Double getMinFlowFeeLast(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    void insertIntoTrscords(BizTransferRecords bizTransferRecords);

    void insertIntoTrscordsDetails(BizTransferRecordsDetail btrd);

    List<BizTransferRecords> posMachineTransferRecords(BizTransferRecords bizTransferRecords);

    int getDetailCount(String detailId);

    List<BizPosMachine> posMachineUnActiveList(@Param("merchId")Long merchId, @Param("channel")String channel, @Param("posCode")String posCode);

    List<BizChannel> getChannelList();

    String getChannelNameByChannel(String channel);

    BizChannel getChannelByChannelId(String channel);

    List<BizTransferRecordsDetail> getPosMachineTransferDetail(BizTransferRecords bizTransferRecords);

    List<BizPictureStore> getPictureList(BizPictureStore bizPictureStore);

    List<BizPictureStore> pictureBackChannels();

    BizTransferRecords getTransferRecords(BizTransferRecords bizTransferRecords);

    CustomerCashBackTemp getCCBTPolicy(Long customerCashBackId);

    List<BizPosMachine> getMachineAboutTemp1();


    TeamOverviewDTO selectPosNumAndActiveNum(@Param("merchId") Long merchId, @Param("channel") String channel,@Param("format") String format);

    List<BizPosMachine> getBackPosCodeList(PosTerminalDTO posTerminalDTO);

    int getBackPosCodeSize(PosTerminalDTO posTerminalDTO);

    void updateMerchIdBySn(@Param("sn")String sn, @Param("merchId")Long merchId);


    List<BizMercahntFeeNameDTO> selectEchoFeeId5563();

    Double getMinVip(@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    List<BizPosMachine> backPosCodeIntervalList(PosTerminalDTO posTerminalDTO);

    void updateFee(@Param("deviceSn") String deviceSn,@Param("feeId") String feeId);

    Double getMinEachFlowFee(@Param("flowFee") String flowFee,@Param("snList")List<String> snList, @Param("merchId")Long merchId);

    BizPosMachine getPosMachineBySnCodeNot0SimAmt(String sn);

    List<String> getPosByMerchIds();

    List<SettlementRateTemplate> querySettlementTemp(BizPosMachine bizPosMachine);
}
